package com.example.androidleanbackdemo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.leanback.widget.ArrayObjectAdapter;
import androidx.leanback.widget.BaseGridView;
import androidx.leanback.widget.FocusHighlightHelper;
import androidx.leanback.widget.HorizontalGridView;
import androidx.leanback.widget.ItemBridgeAdapter;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;

import com.example.androidleanbackdemo.bean.TitleBean;
import com.example.androidleanbackdemo.presenter.TitlePresenter;

public class MainActivity extends AppCompatActivity {
    HorizontalGridView horizontalGridView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    @SuppressLint("RestrictedApi")
    private void initView() {
        horizontalGridView = findViewById(R.id.hg_title);
        horizontalGridView.setItemSpacing(40);
        ArrayObjectAdapter arrayObjectAdapter = new ArrayObjectAdapter(new TitlePresenter());
        ItemBridgeAdapter itemBridgeAdapter = new ItemBridgeAdapter(arrayObjectAdapter);
        horizontalGridView.setAdapter(itemBridgeAdapter);
        horizontalGridView.setFocusScrollStrategy(BaseGridView.FOCUS_SCROLL_ITEM);
        arrayObjectAdapter.addAll(0, TitleBean.getTitleList());
        //设置上焦动画
        FocusHighlightHelper.setupHeaderItemFocusHighlight(itemBridgeAdapter);
    }
}